import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex);

const store = new Vuex.Store({
  // 注册
  plugins: [createPersistedState()],
  state: {
    username: '',
    token: '',
    refreshToken: '',
    fold: false,
    isRefresh: true,
    isOpenDrawer: false,
    isShowLogo: true,
    isShowRefresh: true,
    isShowFullScreen: true,
    language: 'zh',
  },
  mutations: {
    setLanguage(state, language) {
      state.language = language;
    },
    setIsShowLogo(state, bool) {
      state.isShowLogo = bool;
    },
    setIsShowRefresh(state, bool) {
      state.isShowRefresh = bool;
    },
    setIsShowFull(state, bool) {
      state.isShowFullScreen = bool;
    },
    setIsOpenDrawer(state) {
      state.isOpenDrawer = !state.isOpenDrawer;
    },
    setRefresh(state) {
      state.isRefresh = !state.isRefresh;
    },
    setFold(state) {
      state.fold = !state.fold;
    },
    addToken(state, token) {
      state.token = token;
    },
    addrefreshToken(state, refreshToken) {
      state.refreshToken = refreshToken;
    },
    addUser(state, username) {
      state.username = username;
    },
    delUser(state) {
      state.username = '';
    },
    delToken(state) {
      state.token = '';
    },
    delRefreshToken(state) {
      state.refreshToken = '';
    },
  },
});
export default store;
